<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <title>添加医疗机构</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
    <!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>添加医疗机构</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">招标采购管理</a></li>
            <li class="active"><a href="#">采购项目管理</a></li>
            <li class="active"><a href="#">添加医疗机构</a></li>
        </ol>
    </section>
    
    <section class="content">
     <form id="form" method="post" class="form-horizontal">
	   <div class=" box box-success">
		<div class="box-body"  >
		    <div class="input">
		            <div class="textalign1">医疗机构编码：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="hospCode" name="hospCode" placeholder="医疗机构编码"/>
                    </div>
                    <div class="textalign">医疗机名称：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="hospName" name="hospName" placeholder="医疗机名称"/>
                    </div>
                    <div class="textalign"><spring:message code="message.listForm.yiLiaoJiGouFenLei"/>：</div>
                    <div class="boxinput">
                        <select class="textinput" id="hospClassify" name="hospClassify"></select>
                    </div>
		    </div>
		    <div class="input" style="margin-top:-5px">
		            <div class="textalign1">所属地区：</div>
                    <div class="boxinput">
                     <table style="width:100%;">
                       <tr>
                         <td style="width:33%">
                           <select class="textinput"  id="area1" name="area1" disabled="disabled">
                           <option value="${area.areaId }">${area.areaName }</option>
                           </select>
                         </td>
                         <td style="width:33%">  
                           <select class="textinput"  id="area2" name="area2">
                           </select>
                         </td>
                         <td style="width:33%">
                           <select class="textinput"  id="area3" name="area3">
                           </select>
                         </td> 
                        </tr>
                       </table>
                    </div>
                    <div class="textalign">
                       <button type="button" onclick="gridSerch()" class="btn btn-success btn-sm">查&nbsp;询</button>
                    </div>
		    </div>
		</div>
	   </div>
    
    
       <!--<div class=" box box-success">
            <div class="box-body">
                <div class=" form-inline">
                    <div class="form-group form-group-xs">
                        <label for="txtDrugName">医疗机构编码：</label>
                        <input class="form-control" type="text" id="hospCode" name="hospCode" placeholder="医疗机构编码" />
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="txtDrugForm">医疗机名称：</label>
                        <input class="form-control" type="text" id="hospName" name="hospName" placeholder="医疗机名称" />
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="txtDrugForm">医疗机分类：</label>
                        <select class="form-control" style="width: 120px;" id="hospClassify" name="hospClassify">
                        </select>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="txtDrugForm">所属地区：</label>
                        <select class="form-control"  id="area1" name="area1" disabled="disabled">
                        <option value="${area.areaId }">${area.areaName }</option>
                        </select>
                         <select class="form-control"  id="area2" name="area2">
                        </select>
                         <select class="form-control"  id="area3" name="area3">
                        </select>
                    </div>
                    <button type="button" onclick="gridSerch()" class="btn btn-success btn-sm">查&nbsp;询</button>
                </div>
            </div>
        </div>--> 
        </form>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>

        <div class=" box box-warning bottongroup">
            <a href="javascript:void(0);" onclick="batchAddHosp('${projId}');" class="btn btn-default btn-sm">添&nbsp;加</a>
            <!-- <a href="javascript:checkAddHosp();" class="btn btn-default btn-sm" >已添加医疗机构</a> -->
            <a href="${ctx }/bidProject/toList.html" class="btn btn-default btn-sm">返&nbsp;回</a>
        </div>
        <form action="${ctx}/bidProject/toAddedBidProjectHospsList.html" method="post" id="addHospFrom">
        <input type="hidden" name="projId" id="projId">
        <input type="hidden" name="projName" id="projName">
        </form>
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script type="text/javascript">
        $(function () {
            $("#gridlist").jqGrid({
                url: "${ctx}/bidProject/getAddHospDataList.html?projId=${projId}",
                mtype: "POST",
                datatype: "json",
                autowidth: true,
                height: 270,
                colNames: ['hospId', '医疗机构编码', '医疗机构名称', '所属地区', 
                           '<spring:message code="message.listForm.yiLiaoJiGouFenLei"/>',
                           '医疗机构等级', '组织机构代码'],
                colModel: [
                    { name: 'hospId', key:true,hidden:true,width: 40, align: 'center' ,sortable: false},
                    { name: 'hospCode', width: 140 , align:"center",sortable: false,
                    	formatter:function(cellvalue, options, row){ 
                    		return "<a href=\"javascript:$.HN.dialog.opendialog('"+row.hospId+"','医疗机构详情','${pageContext.request.contextPath}/stdHospInfo/hospInfoDetail.html?hospId="+row.hospId+"','800px','400px',function operResult(val){return operResult;})\">"+cellvalue+"</a>"
                    				}
                    },
                    { name: 'hospName', width: 180, align: 'left' ,sortable: false},
                    { name: 'arfullname', width: 180, align: 'center' ,sortable: false},
                    { name: 'hospClassify', width: 150, align: 'center' ,sortable: false,
                    	formatter:function(val, opts, rowdata){
                    		var str="";
                    		if(rowdata.str="1"){
                    			return str="县级及县以上医疗机构";
                    		}else if(rowdata.str="2"){
                    			return str="基层医疗机构";
                    		}else if(rowdata.str="3"){
                    			return str="部队医疗机构";
                    		}else if(rowdata.str="4"){
                    			return str="民营医疗机构";
                    		}
                    		return str;
                    	}},
                    { name: 'hospLevelName', width: 120, align: 'center' ,sortable: false},
                    { name: 'orgCode', width: 90, align: 'center' ,sortable: false}
                ],
                rowNum: 20,
                rowList: [10, 20, 50,100],
                rownumbers: true,
                multiselect: true,
                pager: "#gridpage",
                viewrecords: true,
                caption: "${name} -未添加医疗机构",
                jsonReader: {
                    repeatitems: false  
                },
                //序号宽度自动变化
                gridComplete:function(){     
                    var page = $("#gridlist").jqGrid('getGridParam','page');
                    var rows = $('#gridlist').getGridParam("rowNum");
                    var maxnum = (rows*page).toString();
                    var len = (maxnum.length)*10;
                    $('.jqgfirstrow').find('td').eq(0).css('width',len+'px');
                    $('#gridlist_rn').css('width',len+'px');
                },
                loadComplete: function (data) { //完成服务器请求后，回调函数
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
            
            $("#hospClassify").HNSelect({
                url: "${pageContext.request.contextPath}/selectController/getDicSys.html", data: { ID: '113' },defaultselect:'${form.patternType}',  defaultText: "<option value=''>请选择</option>",
            });
            
            $("#area2").HNSelect({
            	parent_selector: "#area1",  url: "${pageContext.request.contextPath}/selectController/getArea.html", dataid: "ID",defaultText: "<option value=''>请选择</option>",
                func: function () {
                    $("#area3").HNSelect({
                        parent_selector: "#area2", url: "${pageContext.request.contextPath}/selectController/getArea.html", dataid: "ID", defaultText: "<option value=''>请选择</option>",
                        		
                    });
                }
            });
        });
        //查询
        function gridSerch(projId) {
        	var hospCode = $.trim($("#hospCode").val());
        	var hospName = $.trim($("#hospName").val());
        	var hospClassify = $.trim($("#hospClassify").val());
        	var area3 = $.trim($("#area3").val());
        	var area2 = $.trim($("#area2").val());
    		$("#gridlist").jqGrid('setGridParam',{  
    	        datatype:'json',
    	        postData:{"hospCode":hospCode,
    	        		"hospName":hospName,
    	        		"hospClassify":hospClassify,
    	        		"area3":area3,
    	        		"area2":area2,
    	        		"projId":projId},
    	        page : 1
    	    }).trigger("reloadGrid"); //重新载入  
    	}
        //添加
        function addHost(projId,hospId){
        	$.HN.message.confirm("确定添加吗？", "提示信息", "确定").on(function(e) {
        		if (e) {
        	$.ajax({
                url: "${ctx}/bidProject/addHost.html",//action地址
                data: { 
                	"porjId":projId,
            		"hospId":hospId
                },//传值
                type: "post",//执行方式get or post 默认以post方式执行
                success: function (data) {//执行成功后 提示
                	var data  = eval("("+data+")");
                   if ("success" == data){
                	   $.HN.message.alert('添加成功！', '提示信息', 'success');
                	   gridSerch(projId);
                	   return;
                   } else {
                	   $.HN.message.alert('添加失败！', '提示信息', 'error');
                	   return;
                   } 
                },
                error: function () {// 如果执行出现错误 提示
                	$.HN.message.alert('请求出错！', '提示信息', 'success');
                }
            });
        		}
            });
        }
        //批量添加
        function batchAddHosp(projId){
        	var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
    		if (rowIds.length <= 0) {
    			$.HN.message.alert("请选择要操作的行！", "消息", "error");
    			return;
    		}
    		$.HN.message.confirm("确定添加吗？", "提示信息", "确定").on(function(e) {
       		 if(e){
    		var list = [];
    		for (var i=0; i<rowIds.length; i++) {
    			rowId = rowIds[i];
    			list.push({"hospId":rowId, "hospName":projId});
    		}
    		$.post("${ctx}/bidProject/batchAddHosp.html", {
    			"array" : json.jsonToString(list),"projId":"${projId}"
    		}, function(result) {
    			if (result.success) {
    				$.HN.message.alert("添加成功！", "消息", "success");
    				gridSerch(projId);
    			} else {
    				$.HN.message.alert("添加失败！", "消息", "error");
    			}
    		}, "json")
       		 }
    		 
       	 });
    		
        }
       		 
        
        function checkAddHosp(){
    		$("#projId").val("${projId}");
    		$("#projName").val("${proName}");
    		$("#addHospFrom").submit();
    	}
    </script>
</body>
</html>
 